﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XZL.GM.Bll;
using XZL.GM.Dal;

public partial class Admin_Course_CourseList : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindTypeList();
           
            BindCourseList();

        }
    }



    private void BindCourseList()
    {
        int? count = 0;
    //  string str = Request.QueryString["ContainerID"];
        
        int type= Convert.ToInt32(ddlCourseType.SelectedValue);
        int isCharge=Convert.ToInt32(ddlIsCharge.SelectedValue);
        int isLive = Convert.ToInt32(ddlIsLive.SelectedValue);

        divCondition.Visible = true;
        gridList.DataSource = CourseInfoBiz.GetCourseList(txtCourseName.Text.Trim(), type,isCharge,isLive, netPager.CurrentPageIndex, netPager.PageSize, ref count);
        gridList.DataBind();
        netPager.RecordCount = count.Value;
        //lblWarn.Text = "课程数量:" + count.Value;


    }


    private void BindTypeList()
    {
        ddlCourseType.DataSource = CourseInfoBiz.GetCourseTypeList();
        ddlCourseType.DataValueField = "CourseTypeID";
        ddlCourseType.DataTextField = "CourseTypeName";
        ddlCourseType.DataBind();
        ddlCourseType.Items.Insert(0, new ListItem("全部", "0"));
     }

   


    /// <summary>
    /// 分页控件
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void netPager_PageChanged(object sender, EventArgs e)
    {
        BindCourseList();
    }

    protected void btnSelect_Click(object sender, EventArgs e)
    {
        BindCourseList();
        netPager.CurrentPageIndex = 1;
    }


    /// <summary>
    /// 删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>

    //protected void gridList_RowDeleting(object sender, GridViewDeleteEventArgs e)
    //{
    //    string courseID = gridList.DataKeys[e.RowIndex].Value.ToString();
    //    int rID = Convert.ToInt32(courseID);
    //    bool b = CourseInfoBiz.DeleteCourse(rID);
    //    if (b)
    //    {

    //        BindCourseList();
    //    }

    //}
    

    /// <summary>
    /// 删除课程(修改课程状态)
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void gridList_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {

        string courseID = gridList.DataKeys[e.RowIndex].Value.ToString();
        int rID = Convert.ToInt32(courseID);
        Proc_CourseInfo_SelectInfoResult course = CourseInfoBiz.GetCourseInfo(rID);

        int s = 0;
        if (course.Status == -1)
        {
            s = 1;
        }
        else if (course.Status == 1)
        {
            s = -1;
        }

        gridList.Visible = CourseInfoBiz.ChangeStatus(courseID, s);
        BindCourseList();
    }



    
}